package cn.ingrun.utils.auth;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Aspect
@Component
public class LoginAuthAspect {

    private final static Logger logger = LoggerFactory.getLogger(LoginAuthAspect.class);

    private AuthServer authServer;

    @Autowired
    public void setAuthInfo(AuthServer authServer) {
        this.authServer = authServer;
    }

    // 切点
    @Pointcut(value = "@annotation(LoginAuth)")
    public void loginAuth(){ }

    // 前置通知
    @Before("loginAuth()")
    public void doBefore() throws Exception {
        logger.info("check user login");

        if (!authServer.isLogin()){
            throw new Exception("token 不存在或已失效！");
        }
        logger.info("验证通过");
    }





}
